<template>
  <a-modal
    :title="editType == 'detail'?'详情':'审核'"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    okText="确认"
    :class="editType =='detail'?'pic-preview':''"
    :cancelText="editType =='detail'?'关闭':'取消'">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <img v-if="model.Picture" style="width: 50%;
    display: block;
    margin: 0px auto 20px" :src="'https://link.zhangtongshe.com'+model.Picture"/>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="姓名">
          <a-input disabled v-if="model.UserInfo_PersonalInfo_PersonalName" v-decorator="['UserInfo_PersonalInfo_PersonalName']" />
          <a-input :disabled="editType == 'detail'" v-else v-decorator="['UserInfo_PersonalInfo_PersonalName', {rules:[{required:true,message:'请输入'}]}]" />
        </a-form-item>
        <!-- <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="公司信息">
           <a-radio-group @change="changeChoose" name="radioGroup" :disabled="editType == 'detail'" v-decorator="['isChoose', {rules:[{required:true,message:'请选择'}]}]">
              <a-radio :value="1">
                选择公司信息
              </a-radio>
              <a-radio :value="2">
                填写公司信息
              </a-radio>
            </a-radio-group>
        </a-form-item> -->
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          v-if="model.isChoose"
          label="统一信用代码">
          <!-- <a-select :disabled="editType == 'detail'" v-decorator="['CompanyCode', {rules:[{required:true,message:'请输入'}]}]" >
            <a-select-option value="">请选择</a-select-option>
            <a-select-option :value="item.Value" v-for="(item,index) in PositionTagData">{{item.Value}}</a-select-option>
          </a-select> -->
          <a-input placeholder="请选择" disabled @click="showCommonModal" v-decorator="['UserInfo_Company_CompanyCode',{}]"></a-input>
         <!--  <a-input placeholder="请选择" v-if="model.isChoose == 2" v-decorator="['CompanyCode',{}]"></a-input> -->
          
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          v-if="model.isChoose"
          label="公司全称">
          <a-input disabled v-decorator="['UserInfo_Company_CompanyName', {}]" />
          <a-input v-show v-decorator="['UserInfo_CompanyId', {}]" />
          

        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="职务">
          <a-input disabled v-decorator="['UserInfo_PositionTag', {}]" />
            
        </a-form-item>
        <!-- <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="落地园区">
          <a-select :disabled="editType=='detail'" show-search :filter-option="filterOption" placeholder="请选择落地园区" v-decorator="['SubParkId', {}]" >
            <a-select-option value="">请选择</a-select-option>
            <a-select-option :value="item.BaseHighteckParkId" v-for="(item,index) in parkArr">{{item.ParkName}}</a-select-option>
          </a-select>
        </a-form-item> -->
        
        <!-- <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="职务认证">
          <a-select :disabled="editType == 'detail'" v-decorator="['PositionTag', {}]" >
            <a-select-option value="">请选择</a-select-option>
            <a-select-option :value="item.Value" v-for="(item,index) in PositionTagData">{{item.Value}}</a-select-option>
          </a-select>
        </a-form-item> -->
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="服务类型">
          <a-select :disabled="editType=='detail'" show-search placeholder="请选择服务类型" v-decorator="['DemandTagId', {}]" >
            <a-select-option value="">请选择</a-select-option>
            <a-select-option :value="item.BaseInfoId" v-for="(item,index) in DemandTagData">{{item.Value}}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="服务标签">
          <a-input v-decorator="['ServiceTag', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="服务描述">
          <a-input type="textarea" v-decorator="['ServiceRemark', {}]" />
        </a-form-item>
        <!-- <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="邮箱">
          <a-input :disabled="editType == 'detail'" v-decorator="['Email', {rules:[{required:true,message:'请输入'}]}]" />
        </a-form-item> -->
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否通过">
           <a-radio-group @change="changePass" name="radioGroup" :disabled="editType == 'detail'" v-decorator="['isPass', {rules:[{required:true,message:'请输入'}]}]">
              <a-radio :value="1">
                通过
              </a-radio>
              <a-radio :value="2">
                不通过
              </a-radio>
            </a-radio-group>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          v-show="model.isPass == 2"
          label="失败原因">
          <a-input type="textarea" :disabled="editType == 'detail'" v-decorator="['CardRemark',{}]" />
        </a-form-item>
      </a-form>
    </a-spin>
    <commonModal
      modalTitle="公司选择"
      ref="commonModal"
      @getCommonModalData="commonModalData"
      :columns="tableColumns"
      apiUrl="/companyInfo/queryRows"
      :searchArr="searchArr"></commonModal>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import commonModal from '@/components/commonModal'
  export default {
    name: "BaseInfoModal",
    components:{
      commonModal
    },
    watch:{
      visible(newVal,oldVal){
        if(newVal){
          this.editType = sessionStorage.getItem('editType');
        }
      }
    },
    data () {
      return {
        DemandTagData:[],
        tableColumns:[
          { title: '公司全称', dataIndex: 'CompanyName' },
          { title: '公司编码', dataIndex: 'CompanyCode' },
        ],
        searchArr:[
          { label: '公司全称', key: 'CompanyName' },
          { label: '公司编码', key: 'CompanyCode' },
        ],
        parkArr:[],
        PositionTagData:[],
        editType:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        baseinfoid:{rules: [{ required: true, message: '请输入基础ID!' }]},
        typecode:{rules: [{ required: true, message: '请输入类型代码!' }]},
        typename:{rules: [{ required: true, message: '请输入分类名称!' }]},
        value:{rules: [{ required: true, message: '请输入分类值!' }]},
        updatebyid:{rules: [{ required: true, message: '请输入最近更新人!' }]},
        ts:{rules: [{ required: true, message: '请输入最近更新日期!' }]},
        datastatus:{rules: [{ required: true, message: '请输入状态 Y-有效 N-无效!' }]},
        },
        url: {
          add: "/baseInfo/add",
          edit: "/baseInfo/update",
          baseList:"/baseInfo/queryRows",
        },
      }
    },
    created () {
      // this.getPark();
      this.getBaseData();
    },
    methods: {
      getPark(){
        this.$http.postAction("/baseHighteckPark/queryRows",{pageIndex:1,pageSize:9999}).then(res=>{
            if(res.status == 1){
              this.parkArr = res.data.rows;
            }
          })
      },
      showCommonModal () {
        this.$refs.commonModal.open()
      },
      commonModalData(val){
        this.form.setFieldsValue({
          CompanyId:val[0].CompanyId,
          CompanyName:val[0].CompanyName,
          CompanyCode:val[0].CompanyCode,
          OfficeAddress:val[0].OfficeAddress,
        })
      },
      changePass(value){
        this.model.isPass = value.target.value;
        this.$forceUpdate();
      },
      changeChoose(value){
        this.model.isChoose = value.target.value;
        this.$forceUpdate();
      },
      getBaseData(){
        this.$http.postAction(this.url.baseList,{pageNo:1,pageSize:100,selectFields:[],conditions:[{
              "field":"TypeCode",
              "operator":"=",
              "value":'DemandTag'
            }]}).then((res)=>{
          if(res.status == 1){
            this.DemandTagData = res.data.rows;
          }
        })
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        if(this.model.IdentificationId){
          this.model.isChoose = 1;
        }else{
          this.model.isChoose = 2;
        }
        if(this.model.IdentificationStatus_Value == '认证通过'){
          this.model.isPass = 1;
        }else{
          this.model.isPass = 2;
        }
        this.model.DemandTagId = this.model.DemandTag || '';
        // this.model.identificationRemark = this.model.IdentificationRemark?this.model.IdentificationRemark:'';
        // this.model.CompanyCode = this.model.UserInfo_Company_CompanyCode?this.model.UserInfo_Company_CompanyCode:'';
        // this.model.CompanyName = this.model.UserInfo_Company_CompanyName?this.model.UserInfo_Company_CompanyName:'';
        // this.model.CompanyAddress = this.model.UserInfo_Company_OfficeAddress?this.model.UserInfo_Company_OfficeAddress:'';
        // this.model.Phone = this.model.UserInfo_Phone?this.model.UserInfo_Phone:'';
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'UserInfo_PersonalInfo_PersonalName','UserInfo_CompanyId','UserInfo_Company_CompanyCode','UserInfo_Company_CompanyName','UserInfo_PositionTag','CardRemark','isPass','ServiceRemark','ServiceTag','DemandTagId'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            // if(this.model.isPass == 1){
            //   if(!values.CompanyCode){
            //     this.$message.warning('请填写统一信用代码');
            //     return
            //   }
            //   if(!values.CompanyName){
            //     this.$message.warning('请填写公司名称');
            //     return
            //   }
            //   if(!values.Job){
            //     this.$message.warning('请填写职位');
            //     return
            //   }
            // }
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.IdentificationId){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            delete formData.DataStatus;
            formData.UserId = formData.UserInfo;
            if(this.model.isPass == 1){
              //成功
              
              this.$http.postAction('/userCard/certificationPassed',formData,method).then((res)=>{
                if(res.status == 1){
                  that.$message.success('提交成功');
                  that.close();
                  that.$emit('ok');
                }else{
                  that.$message.warning(res.message);
                }
                that.confirmLoading = false;
              })
            }else{
              this.$http.postAction('/userCard/certificationFailed',formData ,method).then((res)=>{
                if(res.status == 1){
                  that.$message.success('提交成功');
                  that.close();
                  that.$emit('ok');
                }else{
                  that.$message.warning(res.message);
                }
                that.confirmLoading = false;
              })
            }
            



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>